﻿using NAutoForm.entity;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace NAutoForm.utils
{
    public class AddressGen
    {
        public static void GetAddress(UserInfo userInfo)
        {

            Assembly _assembly = Assembly.GetExecutingAssembly();
            //项目默认命名空间 + 文件名
            string resourceName = "NAutoForm.resource.AreaData.json";
            Stream stream =_assembly.GetManifestResourceStream(resourceName);
            StreamReader streamReader = new StreamReader(stream);
            string json = streamReader.ReadToEnd();
            List<AreaInfo> areaInfos = JsonConvert.DeserializeObject<List<AreaInfo>>(json);
            Random rd = new Random();
            int index = rd.Next(0, areaInfos.Count - 1);
            userInfo.Address = areaInfos[index].address;
            userInfo.Userid = areaInfos[index].id;
        }
    }
}
